package cn.edu.scau.dropship.ServiceImpl;

import cn.edu.scau.dropship.entity.Company;
import cn.edu.scau.dropship.entity.CompanyExample;
import cn.edu.scau.dropship.mapper.CompanyMapper;
import cn.edu.scau.dropship.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CompanyServiceImpl implements CompanyService {
    @Autowired
    private CompanyMapper companyMapper;

    @Override
    public long countByExample(CompanyExample example) {
        return companyMapper.countByExample(example);
    }

    @Override
    public int deleteByExample(CompanyExample example) {
        return companyMapper.deleteByExample(example);
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return companyMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Company record) {
        return companyMapper.insert(record);
    }

    @Override
    public int insertSelective(Company record) {
        return companyMapper.insertSelective(record);
    }

    @Override
    public List<Company> selectByExample(CompanyExample example) {
        return companyMapper.selectByExample(example);
    }

    @Override
    public Company selectByPrimaryKey(Integer id) {
        return companyMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByExampleSelective(Company record, CompanyExample example) {
        return companyMapper.updateByExampleSelective(record, example);
    }

    @Override
    public int updateByExample(Company record, CompanyExample example) {
        return companyMapper.updateByExample(record, example);
    }

    @Override
    public int updateByPrimaryKeySelective(Company record) {
        return companyMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Company record) {
        return companyMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<Company> selectAll() {
        CompanyExample companyExample=new CompanyExample();
        CompanyExample.Criteria criteria=companyExample.createCriteria();
        criteria.andIdIsNotNull();
        return companyMapper.selectByExample(companyExample);
    }

    @Override
    public Company selectByEname(String name) {
        CompanyExample companyExample=new CompanyExample();
        CompanyExample.Criteria criteria=companyExample.createCriteria();
        criteria.andEnglishNameEqualTo(name);
        List<Company> list = companyMapper.selectByExample(companyExample);
        if(list.size()>0){
            return list.get(0);
        }
        return null;
    }
}
